<CFOUTPUT>
	<link rel="StyleSheet" href="#client.wstheme_path#graph.css" type="text/css">
	<script language="JavaScript1.2" src="#client.common_path#RemoveFromList.js"></script>
	<script language="JavaScript1.2" src="#client.common_path#CheckDigit.js"></script>
	<script language="JavaScript1.2" src="#client.common_path#CheckValue.js"></script>
	<script language="JavaScript1.2" src="#client.common_path#CheckDate.js"></script>
	<script language="VBScript" 	 src="#client.common_path#SearchOnSelect.vb"></script>
	<script language="JavaScript1.2" src="./userfilter.js"></script>
</CFOUTPUT>

<CFSET sDelimiter = "~">
<CFSET sCanUpdate = "">

<!--- Initialize Detail ID (userfilterID) --->
<CFPARAM NAME="form.idDet" DEFAULT="">

<CFIF isDefined("url.idDet") AND not isDefined("form.btnFUNCADD")>
	<CFSET form.idDet = decrypt(url.idDet, client.ek)>
</CFIF>

<!--- get header --->
<CFQUERY NAME="GetHead" DATASOURCE="#client.company_dsn#">
	SELECT *
	FROM ECRGWORKSCHED
	WHERE
		(WSCODE  = '#sTypeID#')	
</CFQUERY>


<!--- get table and its structures --->
<CFQUERY DATASOURCE="#client.global_dsn#" NAME="grgTableFields">
	SELECT TABLENAME, COLUMNNAME, COLUMNDESC, #sqlLOWERCASE#(COLUMNTYPE) as COLUMNTYPE, PICKLIST, PHYSICALWIDTH
	FROM GRGBOSETABLEFIELDS
	WHERE #sqlUPPERCASE#(TABLENAME) = #sqlUPPERCASE#('cmfpa')
	ORDER BY COLUMNNAME, COLUMNDESC, COLUMNTYPE
</CFQUERY>


<CFIF isDefined("url.idDet") AND not isDefined("form.btnUserFilterSelect")>
	<CFSET idDet = decrypt(url.idDet, client.ek)>
	<CFINCLUDE TEMPLATE="./_userfilterqueryData.cfm">
</CFIF>

<CFIF form.idDet NEQ "">
	<CFSET encIdDet = urlEncodedFormat(encrypt(form.idDet,client.ek))>
<CFELSE>
	<CFSET encIdDet = "">
</CFIF>

<!--- display the details records --->
<CFMODULE TEMPLATE="#client.common_path#cfm_wswindow.cfm" TITLE="User Filter for #GetHead.WSDESCRIPTION#">

<TABLE bgColor="#ffffff" width="100%">
<CFOUTPUT>
<FORM ACTION="#getfilefrompath(getbasetemplatepath())#?id=#sTypeIDEnc#" NAME="frmUserFilter" method="post" onsubmit="return SubmitNow();">
</CFOUTPUT>

   <tr>
	<td>
		<CFOUTPUT>
		<input name="btnUserFilterSave" type="submit" value="Save" class="bitbtn" #sCanUpdate#>
		<input name="btnUserFilterBack" type="submit" value="Back" backvalue=0 onclick="this.backvalue=1" class="bitbtn">
		<input name="idDet" type="hidden" value="#encIdDet#">
		<input name="hidFilterType" type="hidden" value="USERDEFINED">
		<CFIF form.idDet NEQ "">
			<CFIF isDefined("url.action")>
				<input name="action" type="hidden" value="#myAction#">
			<CFELSE>
				<input name="action" type="hidden" value="update">
			</CFIF>
		<CFELSE>
			<input name="action" type="hidden" value="new">
		</CFIF>
		</CFOUTPUT>
	<br><hr>
	</td>
   </tr>
   <tr>
	<td nowrap>
	   <table cellpadding="1" cellspacing="0" class="BorderOnly">
		<CFOUTPUT>
		<tr>
			<td>Description</td>
			<CFIF NOT IsDefined("form.btnUserFilterSelect")>
				<td><INPUT TYPE="TEXT" NAME="txtDescription" style="width: 100%;" MAXLENGTH="60" VALUE="#qryCRGUSERFILTER.DESCRIPTION#"></td>
			<CFELSE>
				<td><INPUT TYPE="TEXT" NAME="txtDescription" style="width: 100%;" MAXLENGTH="60"></td>
			</CFIF>
		</tr>
		<tr>
			<td>Table Name</td>
			<td>
			<select style="display:none;" name="availabletable" style="width: 100%" ondblclick="SelectTable()" onkeyUp="vbscript: SearchOnSelect(document.frmUserFilter.availabletable)" DISABLED>
				<option VALUE="CMFPA#sDelimiter#C">CMFPA</option>
			</select>
			<INPUT TYPE= "TEXT" NAME="txtTableName" style="width: 100%;" VALUE="CMFPA" READONLY>
			<select style="display:none;" name="sourcetable" style="width: 100%;" onchange="GetSourceField(nSourceFieldLen, document.frmUserFilter.sourcefield, true, this)">
				<option VALUE="CMFPA">CMFPA</option>
			</select>
			</td>
		</tr>
		</CFOUTPUT>
		<tr><td height="5px" colspan="3">
			<select style="display:none;" size="5" name="tablefield" style="width: 100%" onkeyUp="vbscript: SearchOnSelect(document.frmUserFilter.tablefield)">
			   <CFLOOP QUERY="grgTableFields">
				<CFIF Trim(grgTableFields.PICKLIST) IS "">
					<CFSET sPickList=" ">
				<CFELSE>
					<CFSET sPickList=grgTableFields.PICKLIST>
				</CFIF>

				<CFQUERY NAME="qryLookup" DATASOURCE="#client.global_dsn#">
					SELECT *
					FROM GSTLOOKUP
					WHERE MASTERTABLE = '#grgTableFields.TABLENAME#' AND
						  MASTERFIELD = '#grgTableFields.COLUMNNAME#'
				</CFQUERY>

				<CFIF qryLookup.RecordCount>
					<CFSET sLookup=qryLookup.LOOKUPTABLE & sDelimiter & qryLookup.LOOKUPKEYFIELD & sDelimiter & qryLookup.LOOKUPRESULTFIELD & sDelimiter & ToString(grgTableFields.PHYSICALWIDTH)>
				<CFELSE>
					<CFSET sLookup=" " & sDelimiter & " " & sDelimiter & " " & sDelimiter & " ">
				</CFIF>
				<CFOUTPUT>
				<option search="#grgTableFields.TABLENAME##grgTableFields.COLUMNNAME#" value="#grgTableFields.TABLENAME##sDelimiter##grgTableFields.COLUMNNAME##sDelimiter##LCase(grgTableFields.COLUMNTYPE)##sDelimiter##sPickList##sDelimiter##sLookup##sDelimiter##grgTableFields.COLUMNDESC#">#grgTableFields.TABLENAME#.#grgTableFields.COLUMNNAME# (#grgTableFields.COLUMNDESC#-#grgTableFields.COLUMNTYPE#)</option>
				</CFOUTPUT>
			   </CFLOOP>
			</select>
		    </td>
		</tr>
		<tr>
			<td>Fields</td>
			<CFOUTPUT>
			<td>
				<!---  <select name="sourcefield" style="width: 100%;" onchange="ChangeSourceValue()" #sCanUpdate#>--->
				<select name="sourcefield" style="width: 100%;" #sCanUpdate#>
				<CFLOOP QUERY="grgTableFields">
					<option value="#grgTableFields.COLUMNNAME#">#grgTableFields.COLUMNNAME#</option>
				</CFLOOP>
			   </select>
			</td>
			</CFOUTPUT>
		</tr>
		<tr>
			<td>Source Value</td>
			<td><CFOUTPUT>
			   <div style="display:block" id="svoperator">
				<select name="cnd_operator" onchange="ToggleOperator('cnd_operator')" #sCanUpdate#>
					<option value=" ">&nbsp;</option>
					<option selected value="=">=</option>
					<option value="<>"><></option>
					<option value=">">&gt;</option>
					<option value="<">&lt;</option>
					<option value=">=">&gt;=</option>
					<option value="<=">&lt;=</option>
					<option value="LIKE">LIKE</option>
				</select>
				<input type="Text" name="cnd_value" size="15" maxlength="200" #sCanUpdate#>
			   </div>
			   <div style="display:none" id="svpicklist">
				<select name="picklist" onchange="ToggleOperator('picklist')" #sCanUpdate#><option value=" ">&nbsp;</select>
			   </div>
			   <div style="display:none" id="svlookup">
				<input type="text" readonly size="20" name="lookupkey" fieldname="" tablename="" fieldtype="" onfocus="ToggleOperator('lookupkey')" #sCanUpdate#>
				<a href="javascript: GenerateLookupParams()"><img src="#client.icon_path#lookup.gif" border="0" alt="Select from Lookup"></a>
				<input type="text" readonly size="50" name="lookupdesc" fieldname="" #sCanUpdate#>
			   </div>
			</CFOUTPUT>
			</td>
		</tr>
		<tr>
			<td>Joining Operator&nbsp;&nbsp;&nbsp;</td>
			<td>
				AND&nbsp;<input type="Radio" checked name="cnd_joinoperator" value="AND" #sCanUpdate#>&nbsp;&nbsp;&nbsp;&nbsp;OR
				<input type="Radio" name="cnd_joinoperator" value="OR" #sCanUpdate#>
			</td>
		</tr>
		<tr>
			<td>
				Condition
			</td>
			<td>
				<select size="5" name="condition" multiple style="width: 100%;" #sCanUpdate#>
				<CFIF NOT IsDefined("form.btnUserFilterSelect")>
				   <CFLOOP QUERY="qryCRGUSERFILTERCONDITION">
					<CFSET sValue="#qryCRGUSERFILTERCONDITION.PRIORITYNO##sDelimiter##qryCRGUSERFILTERCONDITION.ALIAS##sDelimiter#" &
						"#qryCRGUSERFILTERCONDITION.SOURCEFIELD##sDelimiter##qryCRGUSERFILTERCONDITION.OPERATOR##sDelimiter#" &
						"#qryCRGUSERFILTERCONDITION.VALUEORALIAS##sDelimiter#">
					<CFSET sText="#qryCRGUSERFILTERCONDITION.ALIAS#.#qryCRGUSERFILTERCONDITION.SOURCEFIELD# #qryCRGUSERFILTERCONDITION.OPERATOR# ">

					<CFIF Trim(#qryCRGUSERFILTERCONDITION.JOININGFIELD#) IS "">
						<CFSET sValue=sValue & " ">

						<CFIF Trim(#qryCRGUSERFILTERCONDITION.VALUEORALIAS#) IS "">
							<CFSET sText=sText & "''">
						<CFELSE>
							<CFSET sText=sText & "#qryCRGUSERFILTERCONDITION.VALUEORALIAS#">
						</CFIF>
					<CFELSE>
						<CFSET sValue=sValue & "#qryCRGUSERFILTERCONDITION.JOININGFIELD#">
						<CFSET sText=sText & "#qryCRGUSERFILTERCONDITION.VALUEORALIAS#.#qryCRGUSERFILTERCONDITION.JOININGFIELD#">
					</CFIF>

					<CFSET sValue=sValue & "#sDelimiter#" & "#qryCRGUSERFILTERCONDITION.JOININGOPERATOR#">

					<CFIF Trim(#qryCRGUSERFILTERCONDITION.GROUPSTART#) IS "">
						<CFSET sValue=sValue & "#sDelimiter# ">
					<CFELSE>
						<CFSET sValue=sValue & "#sDelimiter#" & "#qryCRGUSERFILTERCONDITION.GROUPSTART#">
						<CFSET sText=Replace(qryCRGUSERFILTERCONDITION.GROUPSTART, "(", "( ", "ALL") & " " & sText>
					</CFIF>

					<CFIF Trim(#qryCRGUSERFILTERCONDITION.GROUPEND#) IS "">
						<CFSET sValue=sValue & "#sDelimiter# ">
					<CFELSE>
						<CFSET sValue=sValue & "#sDelimiter#" & "#qryCRGUSERFILTERCONDITION.GROUPEND#">
						<CFSET sText=sText & " " & Replace(qryCRGUSERFILTERCONDITION.GROUPEND, ")", ") ", "ALL")>
					</CFIF>

					<CFSET sText=sText & " #qryCRGUSERFILTERCONDITION.JOININGOPERATOR#">
					<CFOUTPUT>
					<option value="#sValue#">#sText#</option>
					</CFOUTPUT>
				   </CFLOOP>
				</CFIF>
				</select>
			</td>
		</tr>
		<tr>
			<td></td>
			<td>
			<input type="button" class="bitbtn" value="Add" onclick="AddCondition()" class="bitbtn" #sCanUpdate#>
			<input type="button" onclick="RemoveCondition()" value="Delete" class="bitbtn" #sCanUpdate#><input type="button" value="Set Operator" onclick="setOperator()" #sCanUpdate# class="bitbtn"><input type="button" value="Group Expression" onclick="GroupExpression_2()" class="bitbtn" >
			<input type="button" value="Remove Grouping" onclick="RemoveGrouping()" class="bitbtn" >
			<input type="button" value="Move Up" onclick="MoveUp()" class="bitbtn" #sCanUpdate#>
			<input type="button" value="Move Down" onclick="MoveDown()" #sCanUpdate# class="bitbtn">
			</td>
		</tr>
		</table>
	</td>
   </tr>

<SCRIPT>
InitVar();
ChangeSourceValue();
</SCRIPT>
</FORM>
</TABLE>
<CFMODULE TEMPLATE="#client.common_path#cfm_wswindow.cfm" TOP="False">
